import Vue from 'vue'
import Router from 'vue-router'
import {system,CheckToken} from "../methods/request"
import { MessageBox } from 'mint-ui';
import {getOpenId} from "../methods/baseinfo"
Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/',
      name: 'home',
      component: function (resolve) {
        require(['src/components/pages/home/index.vue'], resolve)
      }
    },
    {
      path: '/check',
      name: 'check',
      component: function (resolve) {
        require(['src/components/check'], resolve)
      }
    },
    {
      path: '/login',
      name: 'login',
      component: function (resolve) {
        require(['src/components/login'], resolve)
      }
    },
    {
      path: '/login_inner',
      name: 'login_inner',
      component: function (resolve) {
        require(['src/components/login_inner'], resolve)
      }
    },
    {
      path: '/clerkApply',          //店员申请页面
      name: 'clerkApply',
      component: function (resolve) {
        require(['src/components/pages/clerkApply/index.vue'], resolve)
      }
    },
    {
      path: '/category',
      name: 'category',
      component: function (resolve) {
        require(['src/components/global/Category'], resolve)
      }
    },
    {
      path: '/categoryDetail',
      name: 'categoryDetail',
      component: function (resolve) {
        // require(['src/components/pages/categoryDetail/demo.vue'], resolve)       //商品详情页面重写
        require(['src/components/pages/categoryDetail/index.vue'], resolve)
      }
    },
    {
      path: '/IntergralResults',
      name: 'IntergralResults',
      component: function (resolve) {
        require(['src/components/global/IntergralResults'], resolve)
      }
    },
    {
      path: '/Myorder',
      name: 'Myorder',
      component: function (resolve) {
        require(['src/components/pages/myOrder/index.vue'], resolve)
      }
    },
    {
      path: '/payType',//选择支付方式
      name: 'payType',
      component: function (resolve) {
        require(['src/components/global/payType'], resolve)
      }
    },
    {
        path: '/goodsResult',//实物确认订单页面   统一使用这个页面
        name: 'goodsResult',
        component: function (resolve) {
            require(['src/components/pages/goodsResult/index.vue'], resolve)        //正式页面
            // require(['src/components/pages/goodsResult/demo.vue'], resolve)      //历史保存页面
        }
    },
    {
      path: '/AddressManage',
      name: 'AddressManage',
      component: function (resolve) {
        require(['src/components/global/AddressManage'], resolve)
      }
    },
    {
      path: '/Address',
      name: 'Address',
      component: function (resolve) {
        require(['src/components/global/Address'], resolve)             //旧版添加地址页面,必要时可以删除
      }
    },
    {
        path:'/addAddress',
        name:'AddAddress',
        component:function(resolve){
            require(['src/components/pages/addAddress/index.vue'],resolve)      //新版添加地址页面
        }
    },
    {
      path: '/Addresseditor',
      name: 'Addresseditor',
      component: function (resolve) {
        require(['src/components/global/Addresseditor'], resolve)
      }
    },
    {
      path: '/payMoneyEnd',//实物等待或支付完成
      name: 'PayMoneyEnd',
      component: function (resolve) {
        require(['src/components/pages/payMoneyEnd/index.vue'], resolve)        //新版本结算成功页
        // require(['src/components/pages/payMoneyEnd/demo.vue'], resolve)        //旧版本结算成功页
      }
    },
    {
      path: '/orderMoneyDetail',//实物订单详情
      name: 'orderMoneyDetail',
      component: function (resolve) {
        require(['src/components/pages/orderMoneyDetail/index.vue'], resolve)
        // require(['src/components/pages/orderMoneyDetail/demo.vue'], resolve)
      }
    },
    {
      path: '/orderIntergraDetail',//券订单详情
      name: 'orderIntergraDetail',
      component: function (resolve) {
        require(['src/components/global/orderIntergraDetail'], resolve)
      }
    },
    {
      path: '/Myvouchers',//券订单列表
      name: 'Myvouchers',
      component: function (resolve) {
        require(['src/components/pages/myVouchers/index.vue'], resolve)
      }
    },
    {
      path: '/hkbPayfrom',//汇卡宝支付页面
      name: 'hkbPayfrom',
      component: function (resolve) {
        require(['src/components/global/hkbPayfrom'], resolve)
      }
    },
    {
      path: '/Notfound',//没有权限，无token页面
      name: 'Notfound',
      component: function (resolve) {
        require(['src/components/global/Notfound'], resolve)
      }
    },
    {
      path: '/shopcart',//购物车
      name: 'shopcart',
      component: function (resolve) {
        // require(['src/components/shopmall/shopCart'], resolve)
        require(['src/components/pages/shopCart/index.vue'],resolve) // 重写的购物车部分，完成之后之前的购物车可以删掉了
      }
    },
    {
      path: '/shopResult',//购物车确认订单页面
      name: 'shopResult',
      component: function (resolve) {
        require(['src/components/shopmall/shopResult'], resolve)
      }
    },
    ,
    {
      path: '/shopAddressManage',
      name: 'shopAddressManage',
      component: function (resolve) {
        require(['src/components/shopmall/AddressManage'], resolve)
      }
    },
    {
      path: '/shopAddress',
      name: 'shopAddress',
      component: function (resolve) {
        require(['src/components/shopmall/Address'], resolve)
      }
    },
    {
      path: '/shopAddresseditor',
      name: 'shopAddresseditor',
      component: function (resolve) {
        require(['src/components/shopmall/Addresseditor'], resolve)
      }
    },
    {
      path: '/personalCenter',
      name: 'PersonalCenter',//个人中心
      component: function (resolve) {
        require(['src/components/pages/PersonalCenter/index'], resolve)
      }
    },
    {
      path: '/classification',
      name: 'classification',//分类
      component: function (resolve) {
        require(['src/components/pages/classification/index'], resolve)
      }
    },
    {
      path: '/userSetting',
      name: 'userSetting',//用户设置页面
      component: function (resolve) {
        require(['src/components/pages/userSetting/UserSetting'], resolve)
      }
    },
    {
      path: '/addressMangeSet',
      name: 'addressMangeSet',//用户设置页面
      component: function (resolve) {
        require(['src/components/pages/addressMangeSet/index.vue'], resolve)
        // require(['src/components/pages/addressMangeSet/demo.vue'], resolve)
      }
    },
    {
      path: '/addBank',
      name: 'AddBank',//添加银行卡
      component: function (resolve) {
        require(['src/components/pages/AddBank'], resolve)
      }
    },
    {
      path: '/addBankEnd',
      name: 'AddBankEnd',//添加银行卡提交验证码
      component: function (resolve) {
        require(['src/components/pages/AddBankEnd'], resolve)
      }
    },
    {
      path: '/banklist',
      name: 'Banklist',//银行卡列表
      component: function (resolve) {
        require(['src/components/pages/Banklist'], resolve)
      }
    },
    {
      path: '/wallet',
      name: 'Wallet',//钱包
      component: function (resolve) {
        require(['src/components/pages/wallet/index.vue'], resolve)
      }
    },
    {
        path:'/drawCash',
        name:'drawCash',//提取奖励金
        component:function(resolve){
            require(['src/components/pages/drawCash/index.vue'],resolve)
        }
    },
    {
      path:'/Putforward',
      name:'Putforward',//提取奖励金页面
      component:function(resolve){
          require(['src/components/pages/Putforward/index.vue'],resolve)
      }
    },{
      path:'/CashSucc',
      name:'CashSucc',//提取奖励金成功页面
      component:function(resolve){
          require(['src/components/pages/CashSucc/index.vue'],resolve)
      }
    },
    {
      path: '/VoucherShow',
      name: 'VoucherShow',//券展示与发券
      component: function (resolve) {
        require(['src/components/pages/VoucherShow'], resolve)
      }
    },
    {
      path: '/bindPhone',
      name: 'bindPhone',//绑定手机号
      component: function (resolve) {
        require(['src/components/pages/bindPhone/index.vue'], resolve)
      }
    },
    {
      path: '/BatchApplication',
      name: 'BatchApplication',//批量购券页面
      component: function (resolve) {
        require(['src/components/pages/batchApplication/index.vue'], resolve)
      }
    },
    {
      path: '/ApplicationAudit',
      name: 'ApplicationAudit',//批量申请列表
      component: function (resolve) {
        require(['src/components/pages/applicationAudit/index'], resolve)
      }
    },
    {
      path: '/batchTransfer',
      name: 'batchTransfer',//批量分享列表
      component: function (resolve) {
        require(['src/components/pages/batchTransfer/index.vue'], resolve)
      }
    },
    {
      path: '/couponApplyDetail',
      name: 'couponApplyDetail',//批量申请详情
      component: function (resolve) {
        require(['src/components/pages/couponApplyDetail/index.vue'], resolve)
      }
    },
    {
      path: '/codeCenterPage',
      name: 'codeCenterPage',//关注公众号
      component: function (resolve) {
        require(['src/components/pages/codeCenterPage'], resolve)
      }
    },
    {
      path: '/Batch',
      name: 'Batch',//批量中心
      component: function (resolve) {
        require(['src/components/pages/batch'], resolve)
      }
    },
    {
        path:'/autumn',             //中秋节活动页面面,暂时当作跳转链接
        name:'Autumn',
        component:function(resolve){
            require(['src/components/pages/z-activity/autumn.vue'],resolve)
        }
    },
    {
        path:'/newAutumn',          //中秋活动新页面，之前当作跳转链接
        name:'NewAutumn',
        component:function(resolve){
            require(['src/components/pages/z-activity/newAutumn.vue'],resolve)
        }
    },
    {
        path:'/writeOff',            //用户核销页面，暂时当作跳转链接
        name:'WriteOff',
        component:function(resolve){
            require(['src/components/pages/z-activity/writeOff.vue'],resolve)
        }
    },
    {
        path:'/newWriteOff',            //中秋节活动，用户核销页面
        name:'NewWriteOff',
        component:function(resolve){
            require(['src/components/pages/z-activity/newWriteOff.vue'],resolve)
        }
    },
    {
        path:'/follow',             //关注公众号页面
        name:'Follow',
        component:function(resolve){
            require(['src/components/pages/z-follow/follow.vue'],resolve);
        }
    }
  ]
})


router.beforeEach((to, from, next) => {
  if(to.path === '/'){
    if(sessionStorage.getItem("isHkb")){
      next()
    }else{
        next('/login')
    //   MessageBox.alert('无权限访问').then(action => {
    //       WeixinJSBridge.call('closeWindow');
    //   });
    }  
  }else{
    next()
  }
})
export default router
